function hidepdline() {
    $(".hidepdline").hide();
}
function showpdline() {
    $(".hidepdline").show();
}

var proColumns = [
//     {
//     id: 'proType',
//     title: '项目类型',
//     type: 'string',
//     width: 75,
//     columnClass: 'text-center',
//     resolution: function (value) {
//         var content = '';
//         if (value == "XS") {
//             content += '销售类';
//         } else if (value == "ZL") {
//             content += '战略类';
//         } else if (value == "YF") {
//             content += '研发类';
//         } else if (value == "BM") {
//             content += '部门类';
//         } else if (value == "SW") {
//             content += '事务类';
//         } else {
//             content += '测试类';
//         }
//         return content;
//     }
// },
    {
    id: 'proName',
    title: '项目名称',
    type: 'string',
    columnClass: 'text-center',
}
// , {
//     id: 'myJob',
//     title: '我的角色',
//     type: 'string',
//     columnClass: 'text-center',
// }
// , {
//     id: 'proLv',
//     title: '优先级',
//     type: 'string',
//     width: 60,
//     columnClass: 'text-center',
//     resolution: function (value) {
//         var content = '';
//         if (value == 1) {
//             content += '低';
//         }
//         if (value == 2) {
//             content += '中';
//         }
//         if (value == 3) {
//             content += '高';
//         }
//         return content;
//     }
// }
, {
    id: 'proFzuser',
    title: '项目经理',
    type: 'string',
    width: 80,
    columnClass: 'text-center',
}, {
        id: 'conName',
        title: '合同名称',
        type: 'string',
        width: 300,
        columnClass: 'text-center',
    },{
        id: 'comName',
        title: '客户名称',
        type: 'string',
        width: 300,
        columnClass: 'text-center',
    },
//
{
    id: 'operation',
    title: '操作',
    width: 80,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record) {
        var content = '';
        if (record.proState == "1") {
            if (record.lxId == null || record.lxId == 0) {
                if (record.flag == 0) {
                    // content += '<button class="btn btn-xs btn-info" onclick="proBuild(' + record.id + ');"><i class="fa fa-edit"></i>  立项</button>';
                } else {
                    // content += '<button class="btn btn-xs btn-info"><i class="fa icon-envelope"></i>  立项申请中</button>';
                }
            }
            if (record.proType == "XS") {
                if (record.stageCode >= 2) {
                    // content += '  ';
                    // content += '<button class="btn btn-xs btn-primary" onclick="window.location.href=\'#/startBid/' + record.id + '\'"><i class="icon-briefcase"></i>  投标</button>';
                    // content += '  ';
                    // content += '<button class="btn btn-xs btn-success" onclick="window.location.href=\'#/editPrice/' + record.id + '\'"><i class="icon-file-text-alt"></i> 报价</button>';
                }
            }
        }
        // content += '  ';
        // content += '<button class="btn btn-xs btn-warning" onclick="progress(' + record.id + ');"><i class="icon-retweet"></i>  进展</button>';
        content += '  ';
        content += '<button class="btn btn-xs btn-default" onclick="proinfo(' + record.id + ');"><i class="icon-gear (alias)"></i>  管理</button>';
        return content;
    }
}];

function toProDetail(id) {
    location.href = "#/pro/proDetail?proId=" + id;
}

function findList($scope, CertusJsonAjax) {
    $(".ybsubmit").click(function () {
        $("#proContainer_lb").empty();
        $("#proToolBarContainer_lb").empty();
        var proState = $("#proState").val();
        if (proState==""){
            proState=1;
        }
        CertusJsonAjax.dataInit("findProList", {
            "proType": "",
            "proName": $("#proName").val(),
            "cusName": $("#cusName").val(),
            "conName": $("#conName").val(),
            "proState":proState
        }, proColumns, 'proContainer_lb', 'proToolBarContainer_lb', 20);
    });
    $(".ybsubmit").click();
}


// 项目管理操作
function proinfo(id) {
    var param = id + "_" + 0;
    location.href = '#/toProinfo/' + param;
}
//跳转到项目进展
function progress(id) {
    var param = id + "_" + 1;
    location.href = '#/toProinfo/' + param;
}

//新增投标线索页面
//文件下载权限申请
$(".download-icon").on('click', function () {
    //询问框
    layer.confirm('权限不足，是否申请更高权限？', {
        title: '提示信息',
        btn: ['申请', '取消'] //按钮
    }, function () {
        layer.msg('申请成功', {
            icon: 1
        });
    });
});
//文件上传统一字段
function showfile() {
    $(".hidefile").show();
    $("#ishide").val(1);
}
hidefile();

function hidefile() {
    $(".hidefile").hide();
    $("#ishide").val(0);
}

$(".clear").click(function () {
    $("#fileLevel").val("");
    $("#useRange").val("");
    $("#datetime-2").val("");
    $("#filePower").val("");
    $("#aperFileUrl").val("");
    $("#paperChargeUser").val("");
    $("#file").val("");
});

function ckIsN(value) {
    if (value == "N") {
        $("#pdLine").find("input[type='checkbox']").each(function (i, n) {
            if ($(n).val() != "N") {
                $(n).attr("checked", false);
            }
        });
    } else {
        $("#pdLine").find("input[type='checkbox']").each(function (i, n) {
            if ($(n).val() == "N") {
                $(n).attr("checked", false);
            }
        });
    }
}


function findComList(CertusFormAjax, $scope) {
    $scope.showArea = true;
    $scope.showCus = true;
    $scope.showCompare = true;
    $scope.showSign = true;
    $scope.showHk = true;
    $scope.showPolucy = true;
    $scope.showCompe = true;
    $scope.showMoney = true;
    $scope.showBudget = true;
    $scope.showCtMoney = true;
    $scope.showBsMoney = true;
    $scope.showPhMoney = true;
    $scope.proType = "XS";
    CertusFormAjax.ajax("companyListByViewCode", {}, function (response) {
        $scope.comp = JSON.parse(response.data);
        $scope.company = "STSJT";
        getDept("STSJT");
        getArea("STSJT");
    });

    CertusFormAjax.ajax("getPdlines", {}, function (response) {
        $scope.dd = response.data;
    });

    CertusFormAjax.ajax("findViewCompany", {}, function (response) {
        var data = response.data;
        if (data.indexOf("STSJT") > -1) {
            $scope.isStsjt = true;
        }
        if (data.indexOf("STSGD") > -1) {
            $scope.isGdxx = true;
        }
        if (data.indexOf("HFKJ") > -1) {
            $scope.isHfkj = true;
        }
        if (data.indexOf("isGdxx") > -1) {
            $scope.isStsjt = true;
        }
    });

    CertusFormAjax.ajax("findComList", {}, function (response) {
        var nhlTeams = [];
        var data = response.data;
        for (var i = 0; i < data.length; i++) {
            var arr = {};
            arr.name = data[i].comName + "（" + data[i].comShortName + "）-----" + data[i].userName;
            arr.id = data[i].id;
            nhlTeams.push(arr);
        }
        //自动补全
        var nhl = $.map(nhlTeams, function (obj) {
            return {
                value: obj.name,
                data: { category: obj.id }
            };
        });
        $('#cus').devbridgeAutocomplete({
            lookup: nhl,
            minChars: 1,
            onSelect: function (suggestion) {
                $("#cusId").val(suggestion.data.category);
                var cusName = $("#cus").val().split("-----");
                $("#proName").val(cusName[0]);
            },
            showNoSuggestionNotice: true,
            noSuggestionNotice: 'Sorry, no matching results'
        });
    });

    CertusFormAjax.ajax("getProFiles",{},function (response) {
        var data = response.data;
        $scope.wjList = data;
    });

    this.getDept = function (companyCode) {
        var prt = $scope.proType;
        if (companyCode == undefined || companyCode == null || companyCode == "") {
            companyCode = $("#company").val();
        }
        if (prt == "XS") {
            CertusFormAjax.ajax("xsDeptList", {
                companyCode: companyCode
            }, function (response) {
                $scope.dept = response.data;
            });
        } else {
            CertusFormAjax.ajax("deptedList", {
                companyCode: companyCode
            }, function (response) {
                $scope.dept = JSON.parse(response.data);
            });
        }

        CertusFormAjax.ajax("getNlxRoles",{"company":companyCode},function (response) {
            var data = response.data;
            $scope.rlList = data;
        });
    };
    this.getArea = function (companyCode) {
        if (companyCode == undefined || companyCode == null || companyCode == "") {
            companyCode = $("#company").val();
        }
        CertusFormAjax.ajax("findRegionList", {
            "compCode": companyCode
        }, function (response) {
            $scope.area = response.data;
        });
    };

    $scope.changetp = function () {
        if ($scope.proType == "XS") {
            $("#proName").attr("placeholder", "客户名称+产品名称");
            $("#clueLv").val("");
            $("#clueLv").prop("disabled", "");
            $("#urgency").val(0);
            $("#urgency").prop("disabled", "");
            $("#importance").val(0);
            $("#importance").prop("disabled", "");

            $("#datetime-5").prop("disabled", "");
            $("#datetime-5").val("");
            $("#datetime-6").prop("disabled", "");
            $("#datetime-6").val("");
        } else if ($scope.proType == "BM") {
            $("#proName").attr("placeholder", "部门+年份");
            $("#clueLv").val("2");
            $("#clueLv").prop("disabled", "disabled");
            $("#urgency").val(0);
            $("#urgency").prop("disabled", "disabled");
            $("#importance").val(0);
            $("#importance").prop("disabled", "disabled");

            var date = new Date;
            var year = date.getFullYear();
            $("#datetime-5").prop("disabled", "disabled");
            $("#datetime-5").val(year + "-01-01");
            $("#datetime-6").prop("disabled", "disabled");
            $("#datetime-6").val(year + "-12-31");
        } else {
            $("#clueLv").val("");
            $("#clueLv").prop("disabled", "");
            $("#proName").attr("placeholder", "");
            $("#urgency").val(0);
            $("#urgency").prop("disabled", "");
            $("#importance").val(0);
            $("#importance").prop("disabled", "");
            $("#datetime-5").prop("disabled", "");
            $("#datetime-5").val("");
            $("#datetime-6").prop("disabled", "");
            $("#datetime-6").val("");
        }

        $("#company").val("");
        $scope.dept = [];
        $scope.area = [];
        $("#department").val("");
        $('#datetime').val("");
        $('#datetime-1').val("");
        $('#datetime-3').val("");
        $('#datetime-4').val("");
        if ($scope.proType == "XS") {
            $scope.showArea = true;
            $scope.showCus = true;
            $scope.showCompare = true;
            $scope.showSign = true;
            $scope.showHk = true;
            $scope.showPolucy = true;
            $scope.showCompe = true;
            $scope.showMoney = true;
            $scope.showBudget = true;
            $scope.showCtMoney = true;
            $scope.showBsMoney = true;
            $scope.showPhMoney = true;
            $scope.showFinish = false;
            $scope.showVersion = false;
        } else if ($scope.proType == "ZL" || $scope.proType == "SW" ||
            $scope.proType == "BM") {
            $scope.showArea = false;
            $scope.showCus = false;
            $scope.showCompare = false;
            $scope.showSign = false;
            $scope.showHk = false;
            $scope.showPolucy = false;
            $scope.showCompe = false;
            $scope.showMoney = false;
            $scope.showBudget = false;
            $scope.showCtMoney = true;
            $scope.showBsMoney = true;
            $scope.showPhMoney = true;
            $scope.showFinish = true;
            $scope.showVersion = false;
        } else {
            $scope.showCtMoney = false;
            $scope.showArea = false;
            $scope.showCus = false;
            $scope.showCompare = false;
            $scope.showSign = false;
            $scope.showHk = false;
            $scope.showPolucy = false;
            $scope.showCompe = false;
            $scope.showMoney = false;
            $scope.showBudget = false;
            $scope.showBsMoney = true;
            $scope.showPhMoney = true;
            $scope.showVersion = true;
            $scope.showFinish = false;
        }
    }


    var fileInstantiation = {
        classCateCode: 'NBCPYF', //选定市场类 文档
        fileClassCode: 'LCFJ' //选定合同文件
    }
    var fileInstantiationDisable = {
        classCateCodeDis: true, //文件类目不可修改
        fileClassCodeDis: true //文件类型不可修改
    }
    //调用初始化方法
    initFileUpload($scope, fileInstantiation, fileInstantiationDisable, CertusFormAjax);

    var fileId = "";
    // $(".toRegu").on('click', function () {
    //     fileUpload($scope, function (res) {
    //         fileId = res.data;
    //     }, null, CertusFormAjax);
    //     if (fileId!=""){
    //         layer.msg("上传成功!")
    //     }
    // });

    $(".submit").on('click', function () {
        CertusFormAjax.ajax("getValid", {
            "deptCode": $("#department").val(),
            "beginTime": $("#datetime-5").val(), "endTime": $("#datetime-6").val()
        }, function (result) {
            if (result.data > 0) {
                layer.msg("部门项目已存在", { "time": 1000 });
                return;
            } else {
                CertusFormAjax.ajax("isHasProName", { "proName": $("#proName").val() }, function (response) {
                    if (response.data == true) {
                        layer.msg("项目名称已存在！", { "time": 1000 });
                    } else {
                        if (!certusValidateNotnull()) {
                            return;
                        }

                        if ($("#company").val() == "") {
                            layer.msg("请选择所属公司");
                            return;
                        }

                        if ($("#department").val() == "") {
                            layer.msg("请从列表中选择部门");
                            return;
                        }

                        if ($("#cusId").val() == "") {
                            layer.msg("请从列表中选择客户");
                            return;
                        }

                        var sTime = $("#datetime-5").val();
                        var endTime = $("#datetime-6").val();
                        if (endTime == "") {
                            layer.msg("项目周期结束日期不能为空", { time: 1000 });
                            return;
                        }
                        if (sTime != "") {
                            var startTime = new Date(sTime.replace("/", "-").replace("/", "-"));
                            var endTimes = new Date(endTime.replace("/", "-").replace("/", "-"));
                            if (startTime > endTimes) {
                                layer.msg("项目周期开始日期不能大于结束日期", { time: 1000 });
                                return;
                            }
                        } else {
                            layer.msg("项目周期开始日期不能为空", { time: 1000 });
                            return;
                        }

                        //客户交际费用
                        var ctStartTime = $("#ctStartTime").val();
                        var ctEndTime = $("#ctEndTime").val();
                        if (new Date(ctStartTime.replace("/", "-").replace("/", "-"))
                            > new Date(ctEndTime.replace("/", "-").replace("/", "-"))) {
                            layer.msg("客户交际费用开始时间不能大于结束时间", { time: 1000 });
                            return;
                        }

                        //差旅费用
                        var bsStartTime = $("#bsStartTime").val();
                        var bsEndTime = $("#bsEndTime").val();
                        if (new Date(bsStartTime.replace("/", "-").replace("/", "-"))
                            > new Date(bsEndTime.replace("/", "-").replace("/", "-"))) {
                            layer.msg("差旅费用开始时间不能大于结束时间", { time: 1000 });
                            return;
                        }

                        //采购费用
                        var phStartTime = $("#phStartTime").val();
                        var phEndTime = $("#phEndTime").val();
                        if (new Date(phStartTime.replace("/", "-").replace("/", "-"))
                            > new Date(phEndTime.replace("/", "-").replace("/", "-"))) {
                            layer.msg("采购费用开始时间不能大于结束时间", { time: 1000 });
                            return;
                        }

                        var pdLineCodes = "";
                        if (!$("#pdLine").is(":hidden")) {
                            $("#pdLine").find("input[type='checkbox']:checked").each(function (i, n) {
                                if (i == 0) {
                                    pdLineCodes += $(n).val();
                                } else {
                                    pdLineCodes += "," + $(n).val();
                                }
                            });
                            if (pdLineCodes == "") {
                                layer.msg("至少选择一个产品线", { time: 1000 });
                                return;
                            }
                        }

                        var arr = $("form").serializeArray();
                        var data = {};
                        //上传附件
                        data.fileId = fileId;
                        data.pdLineCodes = pdLineCodes;
                        if ($scope.proType != "XS") {
                            data.isCompare = 0;
                        }
                        if ($scope.proType == "BM") {
                            data.clueLv = 2;
                        }
                        for (var i = 0; i < arr.length; i++) {
                            data[arr[i].name] = arr[i].value;
                        };
                        data.startTime = $("#datetime-5").val();
                        data.endTime = $("#datetime-6").val();
                        data.otherMoneyData = otherMoneyData;
                        data.urgency = $("#urgency").val();
                        data.importance = $("#importance").val();
                        data.rlData = rlData;
                        data.wjData = wjData;
                        // 开启
                        var index = layer.load(1);
                        CertusFormAjax.ajax("addClue", {
                            "params": JSON.stringify(data)
                        }, function () {
                            //关闭
                            layer.close(index);
                            layer.msg("申请成功！");
                            window.history.back();
                        });
                    }
                });
            }
        });
    });

    // $(".clear").on('click',function () {
    //     CertusFormAjax.ajax("test",{},function (response) {
    //
    //     });
    //
    // })
}


//涉及文件
var wjColumns = [{
    id: 'wjName',
    title: '文件名称',
    type: 'string',
    columnClass: 'text-center'
}, {
    id: 'comments',
    title: '说明',
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'operation',
    title: '操作',
    width: 75,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record) {
        var content = '';
        content += '<button class="btn btn-xs btn-danger" onclick="deleteWj(' + record.pwid + ');"><i class="fa fa-trash-o"></i>  删除</button>';
        return content;
    }
}];
var wjData = [];
var wjOption = {
    lang: 'zh-cn',
    ajaxLoad: false,
    extraWidth: 20,
    // loadURL:'url',
    exportFileName: '涉及文件列表',
    datas: wjData,
    columns: wjColumns,
    gridContainer: 'wjContainer',
    toolbarContainer: 'wjToolBarContainer',
    tools: ''
};
var wjGrid = $.fn.dlshouwen.grid.init(wjOption);
wjGrid.load();
var pwid = 1;
$(".wjSubmit").click(function () {
    // var wjId = $("#wjName").val();
    // if (wjId==""){
    //     layer.msg("请选择文件！");
    //     return;
    // }
    // var wjName = $('#wjName option:selected').text();
    var wjName = $("#wjName").val();
    var comments = $("#wjComments").val();
    var arr = {};
    arr.pwid = pwid;
    // arr.productCode = wjId;
    arr.productCode = "";
    arr.wjName = wjName;
    arr.comments = comments;
    for(var i=0;i<wjData.length;i++){
        if (wjData[i].pwid==pwid){
            layer.msg("文件已经存在！");
            return;
        }
    }
    pwid++;

    wjData.push(arr);
    wjGrid.load();
    $(".wjhider").hide();
    cleanWj()
});

function deleteWj(pwid) {
    layer.confirm('确认删除此数据？', {
        btn: ['确认', '取消'] //按钮
    }, function () {
        var dArr = {};
        for (var i = 0; i < wjData.length; i++) {
            if (wjData[i].pwid == pwid) {
                dArr = wjData[i];
            }
        }
        wjData.splice($.inArray(dArr, wjData), 1);
        wjGrid.load();
        layer.msg('删除成功');
    });
}

var rlColumns = [{
    id: 'roleName',
    title: '角色',
    type: 'string',
    columnClass: 'text-center'
},{
    id: 'rtMoney',
    title: '级别',
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '';
        if (value=="1"){
            content = "低";
        }else if (value=="2"){
            content = "中";
        }else{
            content = "高";
        }
        return content;
    }
},{
    id: 'beginTime',
    title: '开始时间',
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'endTime',
    title: '结束时间',
    type: 'string',
    columnClass: 'text-center',
},{
    id: 'rtNum',
    title: '人天',
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'comments',
    title: '说明',
    type: 'string',
    columnClass: 'text-center',
}, {
    id: 'operation',
    title: '操作',
    width: 75,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '';
        content += '<button class="btn btn-xs btn-danger" onclick="deleteRl(' + record.rid + ');"><i class="fa fa-trash-o"></i>  删除</button>';
        return content;
    }
}];
var rlData = [];
var rlOption = {
    lang: 'zh-cn',
    ajaxLoad: false,
    extraWidth: 20,
    // loadURL:'url',
    exportFileName: '人力成本列表',
    datas: rlData,
    columns: rlColumns,
    gridContainer: 'rlContainer',
    toolbarContainer: 'rlToolBarContainer',
    tools: ''
};
var rlGrid = $.fn.dlshouwen.grid.init(rlOption);
rlGrid.load();

var rid = 1;
$(".rlSubmit").click(function () {
    var rArr = {};
    var userName = $('#rluserName option:selected').text();
    var userId = $("#rluserName").val();
    if (userId==""){
        layer.msg("请选择角色！");
        return;
    }
    var rtMoney = $("#rtMoney").val();
    var rlBeginTime = $("#rlBeginTime").val();
    var rlEndTime = $("#rlEndTime").val();
    if (rlBeginTime==""||rlEndTime==""){
        layer.msg("请输入使用周期！");
        return;
    }
    var rtNum = daysBetween(rlBeginTime,rlEndTime);
    var rlComments = $("#rlComments").val();
    rArr.roleName = userName;
    rArr.roleId = userId;
    rArr.rtMoney = rtMoney;
    rArr.beginTime = rlBeginTime;
    rArr.endTime = rlEndTime;
    rArr.comments = rlComments;
    rArr.rtNum = rtNum;
    rArr.rid = rid;
    //判断成员是否已经存在
    for(var i=0;i<rlData.length;i++){
        if (rlData[i].roleId==userId){
            layer.msg("成员已经存在！");
            return;
        }
    }
    rid++;
    rlData.push(rArr);
    rlGrid.load();
    $(".hiderl").hide();
    cleanRl()
});

//删除人力
function deleteRl(rid) {
    layer.confirm('确认删除此数据？', {
        btn: ['确认', '取消'] //按钮
    }, function () {
        var dArr = {};
        for (var i = 0; i < rlData.length; i++) {
            if (rlData[i].rid == rid) {
                dArr = rlData[i];
            }
        }
        rlData.splice($.inArray(dArr, rlData), 1);
        rlData.load();
        layer.msg('删除成功');
    });
}
function cleanRl() {
    $("#rluserName").val("");
    $("#rlBeginTime").val("");
    $("#rlEndTime").val("");
    $("#rlComments").val();
}
//人天预估 结束

function showRl() {
    $(".hiderl").show();
}
function showWj() {
    $(".wjhider").show();
};

function hideRl() {
    $(".hiderl").hide();
    cleanRl();
}
function hideWj() {
    $(".wjhider").hide();
}
function cleanWj() {
    $("#wjName").val("");
    $("#wjComments").val("");
}

function proBuild(proId) {
    location.href = "#/toLxsq/" + proId;
}
//所属公司change事件
function findDept() {
    getDept();
    getArea();
}
//项目其他费用表单显示隐藏
function hideother() {
    $(".hideother").hide();
};

function showother() {
    $(".hideother").show();
};
var otherColumns = [{
    id: 'bugetMoney',
    title: '预算金额',
    width: 150,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'budgetBegin',
    title: '开始时间',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'budgetEnd',
    title: '结束时间',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
}, {
    id: 'comments',
    title: '事由',
    type: 'string',
    columnClass: 'text-left',
}, {
    id: 'operation',
    title: '操作',
    width: 75,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record) {
        var content = '';
        content += '<button class="btn btn-xs btn-danger" onclick="deleteWarn(' + record.id + ');"><i class="fa fa-trash-o"></i>  删除</button>';
        return content;
    }
}];
var otherMoneyData = [];
var otherOption = {
    lang: 'zh-cn',
    ajaxLoad: false,
    extraWidth: 20,
    // loadURL:'url',
    exportFileName: '其他费用',
    datas: otherMoneyData,
    columns: otherColumns,
    gridContainer: 'otherContainer',
    toolbarContainer: 'otherToolBarContainer',
    tools: '',
    pageSize: 10,
    pageSizeLimit: [10, 15, 20]
};
var otherGrid = $.fn.dlshouwen.grid.init(otherOption);
otherGrid.load();

var om = 1;

function addOtherMoney() {
    var bugetMoney = $("#bugetMoney").val();
    if (bugetMoney == null || bugetMoney == "" || bugetMoney == undefined) {
        layer.msg('预算金额不能为空!');
        return;
    }
    var comments = $("#comments").val();
    if (comments == null || comments == "" || comments == undefined) {
        layer.msg('事由不能为空!');
        return;
    }
    var arr = {};
    arr.id = om;
    arr.bugetMoney = bugetMoney;
    arr.comments = comments;
    var budgetBegin = $("#oStartTime").val();
    var budgetEnd = $("#oEndTime").val();
    if (budgetBegin == null || budgetBegin == "" || budgetBegin == undefined) {
        layer.msg('开始日期不能为空!');
        return;
    }
    if (budgetEnd == null || budgetEnd == "" || budgetEnd == undefined) {
        layer.msg('结束日期不能为空!');
        return;
    }
    if (new Date(budgetBegin.replace("/", "-").replace("/", "-")) >
        new Date(budgetEnd.replace("/", "-").replace("/", "-"))) {
        layer.msg('开始日期不能大于结束日期!');
        return;
    }
    arr.moneyType = $("#moneyType").val();
    arr.budgetBegin = budgetBegin;
    arr.budgetEnd = budgetEnd;
    otherMoneyData.push(arr);
    om++;
    otherGrid.load();
    $(".hideother").hide();

    $("#bugetMoney").val("");
    $("#oStartTime").val("");
    $("#oEndTime").val("");
    $("#comments").val("");
}

function deleteWarn(wid) {
    layer.confirm('确认删除此数据？', {
        btn: ['确认', '取消'] //按钮
    }, function () {
        var dArr = {};
        for (var i = 0; i < otherMoneyData.length; i++) {
            if (otherMoneyData[i].id == wid) {
                dArr = otherMoneyData[i];
            }
        }
        otherMoneyData.splice($.inArray(dArr, otherMoneyData), 1);
        otherGrid.load();
        layer.msg('删除成功');
    });
};

function daysBetween(sDate1,sDate2){
    //Date.parse() 解析一个日期时间字符串，并返回1970/1/1 午夜距离该日期时间的毫秒数
    var time1 = Date.parse(new Date(sDate1));
    var time2 = Date.parse(new Date(sDate2));
    var nDays = Math.abs(parseInt((time2 - time1)/1000/3600/24));
    return  nDays;
};